#
# Copyright (C) [2024] Xingyun Integrated Circuit, Inc.
#
# GreenCode was a private technology asset of Xingyun Integrated Circuit， Inc （Confidential）
# Author: Shawn.Tan
# Date: 2025.10.28
#
# History: Initial Version 2025.10.28
#
#
from gpgpu.EnvGPGPU import EnvGPGPU
from gpgpu.GenThreadGPGPU import GenThreadGPGPU

from base.Sequence import Sequence


class MainSequence(Sequence):
    def generate(self, **kargs):
        if self.getGlobalState("AppRegisterWidth") == 32:
            random_instructions = [
                "ADD##CALM",
                "SRLI#RV32I#CALM",
                "ADDI##CALM",
                "SLLI#RV32I#CALM",
                "LUI##CALM",
            ]
        else:
            random_instructions = [
                "ADDW##CALM",
                "SRLI#RV64I#CALM",
                "ADDI##CALM",
                "SLLI#RV64I#CALM",
                "LUI##CALM",
            ]

        for _ in range(10):
            for _ in range(self.random32(0, 5)):
                self.genInstruction(self.choice(random_instructions))

        self.genInstruction("MRET##CALM", {"NoSkip": 1, "priv": 1})

        for _ in range(10):
            for _ in range(self.random32(0, 5)):
                self.genInstruction(self.choice(random_instructions))

        self.genInstruction("SRET##CALM", {"NoSkip": 1, "priv": 0})

        for _ in range(10):
            for _ in range(self.random32(0, 5)):
                self.genInstruction(self.choice(random_instructions))


# Points to the MainSequence defined in this file
MainSequenceClass = MainSequence

# Using GenThreadGPGPU by default, can be overriden with extended classes
GenThreadClass = GenThreadGPGPU

# Using EnvGPGPU by default, can be overriden with extended classes
EnvClass = EnvGPGPU
